from django import forms
from .models import Student, Teacher, Course, StudentScore, TeacherRating

class StudentForm(forms.ModelForm):
    class Meta:
        model = Student
        fields = '__all__'
        widgets = {
            'admission_date': forms.DateInput(attrs={'type': 'date'}),
        } 

class TeacherForm(forms.ModelForm):
    class Meta:
        model = Teacher
        fields = '__all__'
        widgets = {
            'hire_date': forms.DateInput(attrs={'type': 'date'}),
        } 

class CourseForm(forms.ModelForm):
    class Meta:
        model = Course
        fields = '__all__'

class StudentScoreForm(forms.ModelForm):
    class Meta:
        model = StudentScore
        fields = ['student', 'score']
        
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        if self.instance and self.instance.student_id:
            self.fields['student'].widget.attrs['readonly'] = True

class TeacherRatingForm(forms.ModelForm):
    class Meta:
        model = TeacherRating
        fields = ['rating', 'comment']
        widgets = {
            'rating': forms.RadioSelect(choices=[(i, str(i)) for i in range(1, 6)]),
            'comment': forms.Textarea(attrs={'rows': 4}),
        } 